package com.ruoyi.system.controller;

import java.nio.charset.Charset;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import cn.hutool.core.net.URLDecoder;
import cn.hutool.core.util.ObjectUtil;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.ServletUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TbDriverCarInfo;
import com.ruoyi.system.service.ITbDriverCarInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 司机车辆信息Controller
 * 
 * @author ruoyi
 * @date 2025-04-11
 */
@RestController
@RequestMapping("/system/driver_car")
public class TbDriverCarInfoController extends BaseController
{
    @Autowired
    private ITbDriverCarInfoService tbDriverCarInfoService;
    @Autowired
    private RedisCache redisCache;
    /**
     * 查询司机车辆信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:driver_car:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbDriverCarInfo tbDriverCarInfo)
    {
        startPage();
        Object company = ServletUtils.getRequest().getHeader("company");
        if(ObjectUtil.isNotNull(company))
        {
            tbDriverCarInfo.setCompany(URLDecoder.decode(company.toString(), Charset.defaultCharset()));
        }
        List<TbDriverCarInfo> list = tbDriverCarInfoService.selectTbDriverCarInfoList(tbDriverCarInfo);
        return getDataTable(list);
    }

    /**
     * 导出司机车辆信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:driver_car:export')")
    @Log(title = "司机车辆信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbDriverCarInfo tbDriverCarInfo)
    {
        Object company = ServletUtils.getRequest().getHeader("company");
        if(ObjectUtil.isNotNull(company))
        {
            tbDriverCarInfo.setCompany(URLDecoder.decode(company.toString(), Charset.defaultCharset()));
        }
        List<TbDriverCarInfo> list = tbDriverCarInfoService.selectTbDriverCarInfoList(tbDriverCarInfo);
        ExcelUtil<TbDriverCarInfo> util = new ExcelUtil<TbDriverCarInfo>(TbDriverCarInfo.class);
        util.exportExcel(response, list, "司机车辆信息数据");
    }

    /**
     * 获取司机车辆信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:driver_car:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbDriverCarInfoService.selectTbDriverCarInfoById(id));
    }

    /**
     * 新增司机车辆信息
     */
    @PreAuthorize("@ss.hasPermi('system:driver_car:add')")
    @Log(title = "司机车辆信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbDriverCarInfo tbDriverCarInfo)
    {
        return toAjax(tbDriverCarInfoService.insertTbDriverCarInfo(tbDriverCarInfo));
    }

    /**
     * 修改司机车辆信息
     */
    @PreAuthorize("@ss.hasPermi('system:driver_car:edit')")
    @Log(title = "司机车辆信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbDriverCarInfo tbDriverCarInfo)
    {
        return toAjax(tbDriverCarInfoService.updateTbDriverCarInfo(tbDriverCarInfo));
    }

    /**
     * 删除司机车辆信息
     */
    @PreAuthorize("@ss.hasPermi('system:driver_car:remove')")
    @Log(title = "司机车辆信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbDriverCarInfoService.deleteTbDriverCarInfoByIds(ids));
    }
}
